//
//  VisitorLoginView.swift
//  SinaWeibo
//
//  Created by 郭平 on 15/10/6.
//  Copyright © 2015年 郭平. All rights reserved.
//

import UIKit

protocol VisitorLoginViewDelegate: NSObjectProtocol {
    // 注册
    func visitorWillRegister()
    // 登陆
    func visitorWillLogin()
}


class VisitorLoginView: UIView {

    weak var visitorViewDelegate: VisitorLoginViewDelegate?
    
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var smallIcon: UIImageView!
    
    @IBOutlet weak var tipLabel: UILabel!
    func setUIInfo(imageName name: String, tipText: String, isHome: Bool = false){
        
        iconView.image = UIImage(named: name)
        tipLabel.text = tipText
        smallIcon.hidden = !isHome
        
        if isHome {
            startAnimation()
        }
        
    }
    // 注册
    @IBAction func registerAction(sender: AnyObject) {
        visitorViewDelegate?.visitorWillRegister()
    }
    
    // 登陆
    @IBAction func loginAction(sender: AnyObject) {
        visitorViewDelegate?.visitorWillLogin()
    }
    // 动画
    private func startAnimation(){
       
        let anim = CABasicAnimation(keyPath:"transform.rotation")
        // 循环次数
        anim.repeatCount = MAXFLOAT
        // 一圈循环时间
        anim.duration = 20
        // 循环半径
        anim.toValue = 2 * M_PI
        // 是否在当前页面不活跃时候移除
        anim.removedOnCompletion = false
        // 添加
        smallIcon.layer.addAnimation(anim, forKey: nil)
    }
    

}
